Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding uniqueItems property to Set schemas #3604

Merged
merged 3 commits into from
Mar 14, 2024
Merged

Conversation

ghik
Copy link
Contributor

@ghik ghik commented Mar 14, 2024

@ghik ghik force-pushed the set-schema-unique-items branch from 8ae4e10 to d579f40 Compare March 14, 2024 08:31
@@ -301,6 +301,8 @@ object Schema extends LowPrioritySchema with SchemaCompanionMacros {
implicit def schemaForOption[T: Schema]: Schema[Option[T]] = implicitly[Schema[T]].asOption
implicit def schemaForArray[T: Schema]: Schema[Array[T]] = implicitly[Schema[T]].asArray
implicit def schemaForIterable[T: Schema, C[X] <: Iterable[X]]: Schema[C[T]] = implicitly[Schema[T]].asIterable[C]
implicit def schemaForSet[T: Schema, C[X] <: scala.collection.Set[X]]: Schema[C[T]] =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This relies on Scala implicit priority rules, specifically the fact that schemaForSet is "more specific" than schemaForIterable. It seems to work fine in tests, but I always feel a bit anxious when I need to rely on these rules, and in this case it seems to be the first implicit definition to do so.
I just hope we don't introduce some crazy implicit ambiguities into tapir user's projects...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll find out soon enough :)

@ghik ghik marked this pull request as ready for review March 14, 2024 09:55
@ghik ghik requested a review from adamw March 14, 2024 09:55
@adamw adamw merged commit 08628a8 into master Mar 14, 2024
28 checks passed
@adamw adamw deleted the set-schema-unique-items branch March 14, 2024 11:31
@adamw
Copy link
Member

adamw commented Mar 14, 2024

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Json Schema - Include uniqueItems when array is created from Set
2 participants